// pages/order/order.jsimport {
  import { picUrl, formatTime } from '../../utils/util.js';
import { indexFeed2, userOrder, conventionDetail } from '../../utils/getData.js'
const getopen = require('../../utils/maxutil.js');
const app = getApp();

Page({

  /**
   * 页面的初始数据
   */
  data: {
    data:'',
    convention:'',
    orderList:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options)
    // let conventionId = 'd794ef18aaf642b1a549c4627870f7e1';
    // let orderId = '2a4f5e58d92a4e269009d921a5204eab';
    this.getdetail(options.conventionId);
    this.userOrder(options.orderId)

  },
  getdetail(conventionId){
    let than = this;
   let data = {
     userId:wx.getStorageSync('userId'),
     conventionId:conventionId,
   }

   conventionDetail(data).then( function (res){
     console.log(res)
     if(res.success){
       let convention = res.result
       let data = {
         ...convention,
         conventionCoverPage:picUrl('activity/img/',convention.conventionCoverPage),
         conventionBlurCoverPage:picUrl('activity/img/',convention.conventionBlurCoverPage),
         detailImg:picUrl('activity/img/',convention.detailImg),
         shareImg:picUrl('activity/img/',convention.shareImg),
         conventionDate:convention.conventionDate.slice(5).replace("-","/"),
        //  conventionUserMap:convention.conventionUserMap.participantlist.map((item)=>{
        //    return {...item, avatarPath:picUrl('',item.avatarPath), userPic:picUrl('',item.userPic)}
        //  }),
         sponsorUser:{...convention.sponsorUser,avatarPath:picUrl('',convention.sponsorUser.avatarPath)}
       }
       wx.setStorageSync('lookCoverPage', data.conventionCoverPage); //在看的主题图片(局或者活动)，登录流程需要用到

       //判断活动是否结束
       let currentTime = formatTime(new Date()); //当前时间
       currentTime = currentTime.substring(0,currentTime.length-3);
       let conventionEndTime = convention.conventionDate.replace(/-/g,"/") +' '+ convention.conventionEndTime  //活动结束时间
       console.log('活动结束时间')
       console.log(currentTime >= conventionEndTime)

          //局汇总需要的基础数据，避免重复打接口
          let conventioninfo = {
            conventionName:data.conventionName,
            conventionDate:data.conventionDate,
            conventionBeginTime:data.conventionBeginTime,
            conventionEndTime:data.conventionEndTime,
            conventionAddress:data.conventionAddress,
            conventionCoverPage:data.conventionCoverPage,
            conventionBlurCoverPage:data.conventionBlurCoverPage,
            conventionImageRGB:data.conventionImageRGB,
            // conventionInvalidation:currentTime >= conventionEndTime, //活动是否失效
            // conventionInvalidation:false, //未结束
          }
          // app.globalData.conventionInfo = conventioninfo

          than.setData({
            convention:conventioninfo,
            // isloding:true,
            // headerdata,
          })
     }
   })
 },

//局详情
// getActivityDetail(activityId){
//   let than = this;
//   //因多个页面会有局详情接口，使用公共方法转换数据，只需要传activityId
//   getopen.getActivityDetail(activityId).then( res =>{
//     console.log(res)
//     let conventioninfo = {
//       conventionName:res.activityName,
//       conventionDate:res.activityDate,
//       conventionBeginTime:res.activityBeginTime,
//       conventionEndTime:res.activityEndTime,
//       conventionAddress:res.activityAddress,
//       conventionCoverPage:res.activityCoverPage,
//       conventionBlurCoverPage:res.activityBlurCoverPage,
//       conventionImageRGB:res.activityImageRGB,
//       conventionInvalidation:res.activityInvalidation,
//     }
//     than.setData({
//       data:res,
//       convention:conventioninfo,
//     })

//   })
// },

  //用户-支付回调页面
  userOrder(orderId){
    let than = this;
    let data={
      orderId:orderId
    }
    userOrder(data).then(res=> {
      console.log(res)
      let newlist = []
    res.result.map(a=> {
      a.orderQRCodes.map((b,index)=> {
        let c = {...b,ticketNums:a.ticketNums,currentNums:index+1}
        newlist.push(c)
      })
    })
      if(res.success){
        than.setData({
          // payOver:true,
          // isbookedListShow:true,
          // payPopover:false,
          swiperTab:0,
          orderList:newlist
        })
      }
    })
  },

 //轮播图，左箭头
 swipeLeft(){
  const { swiperTab } = this.data;
  if(swiperTab ==0) return false
  this.setData({
   swiperTab:swiperTab-1
  })
},
//轮播图，右箭头
swiperRight(){
 const { swiperTab, orderList } = this.data;
 if(swiperTab == orderList.length-1) return false;
 this.setData({
  swiperTab:swiperTab+1
 })
},
//轮播图，主体部份滑动事件
swiperChange: function( e ) {
 var that = this;
 that.setData( { swiperTab: e.detail.current });
},
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})